package com.lzq.leetcode.lanqiao;

import java.util.Arrays;
import java.util.Scanner;

public class s1037 {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...

        String string = scan.nextLine();
        scan.close();
        char[] chs = string.toCharArray();
        int len = string.length();
        long sum = 0;

        int[] pos = new int[26];
        Arrays.fill(pos, -1);

        // 遍历
        for (int i=0; i<len; i++) {
            int prePos = pos[chs[i] - 'a'];
            if (prePos == -1) {
                // 如果之前没有出现过
                sum += (long) (i + 1) *  (len - i);
            } else {
                // 之前出现过
                sum +=  (long) (i - prePos) * (len - i);

            }
            pos[chs[i] - 'a'] = i;
        }

        System.out.println(sum);
    }
}
